﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ToolsLayer;
using DevExpress.XtraCharts;

namespace Webcar.UI
{
    public partial class SecStudyPanel : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(this.IsPostBack) return;
            DataSet ds = DB.ExecuteDataset(@"select b.DEPT_CODE,ny,COUNT(1) nums from SEC_DRV_STUDY a,BS_EMP b
                where a.MAN_CODE = b.MAN_CODE and ny between '2008-01' and '2008-10'
                group by ny,b.DEPT_CODE");
            DataSet ds_dept = DB.ExecuteDataset("select * from dept");


            
            foreach (DataRow row in ds_dept.Tables[0].Rows)
            {
                Series series1 = new Series(row["dept_name"].ToString(), ViewType.Line);
                this.WebChartControl1.Series.Add(series1);
                for (int i = 1; i <= 10; i++)
                {
                    string ny = "2008-0"+i.ToString();
                    DataRow[] rows = ds.Tables[0].Select("ny='" + ny + "' and dept_code='"+row["dept_code"].ToString()+"'");
                    if (rows.Length > 0)
                    {
                        double[] values = new double[rows.Length];
                        for (int k = 0; k < rows.Length; k++)
                        {
                            values[k] = double.Parse(rows[k]["nums"].ToString());
                        }
                        series1.Points.Add(new SeriesPoint(ny, values));
                    }
                }
                //DataRow[] rows = ds.Tables[0].Select("dept_code='" + row["dept_code"].ToString() + "'");
                //if (rows.Length > 0)
                //    series1.Points.Add(new SeriesPoint(row["dept_name"].ToString(), int.Parse(rows[0]["nums"].ToString())));
                //else
                //    series1.Points.Add(new SeriesPoint(row["dept_name"].ToString(), 0));
            }
            
        }
    }
}